/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ftpcombiner.gui.applicationframe;

import ftpcombiner.ApplicationController;
import ftpcombiner.gui.GUILoader;
import ftpcombiner.gui.ModifyServersDialog;
import ftpcombiner.listeners.DeleteListener;
import ftpcombiner.listeners.DownloadListener;
import ftpcombiner.listeners.UploadListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

/**
 *
 * @author Ben
 */
public class MenuBar extends JMenuBar implements GUILoader {

    private ServerMenu serverMenu;
    private TransferMenu transferMenu;
    private ModifyMenu modifyMenu;

    private void init() {
        initializeComponents();
        setLayouts();
        addComponents();
        addComponentListeners();
        otherInit();
    }

    public MenuBar() {
        init();
    }

    @Override
    public void initializeComponents() {
        serverMenu = new ServerMenu();
        transferMenu = new TransferMenu();
        modifyMenu = new ModifyMenu();
    }

    @Override
    public void addComponents() {
        add(serverMenu);
        add(transferMenu);
        add(modifyMenu);
    }

    @Override
    public void addComponentListeners() {
    }

    @Override
    public void otherInit() {
        ApplicationController.getSplashScreen().incrementProgress();
    }

    @Override
    public void setLayouts() {
    }

    private class ServerMenu extends JMenu implements GUILoader {

        private JMenuItem modifyServersItem;

        private void init() {
            initializeComponents();
            setLayouts();
            addComponents();
            addComponentListeners();
            otherInit();
        }

        public ServerMenu() {
            init();
        }

        @Override
        public void initializeComponents() {
            modifyServersItem = new JMenuItem("Add or Remove Servers");
        }

        @Override
        public void addComponents() {
            add(modifyServersItem);
        }

        @Override
        public void addComponentListeners() {
            modifyServersItem.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseReleased(MouseEvent e) {
                (new ModifyServersDialog()).setVisible(true);
            }
        });
        }

        @Override
        public void otherInit() {
            setText("Servers");
            ApplicationController.getSplashScreen().incrementProgress();
        }

        @Override
        public void setLayouts() {
        }
    }

    private class TransferMenu extends JMenu implements GUILoader {

        private JMenuItem uploadItem, downloadItem;

        private void init() {
            initializeComponents();
            setLayouts();
            addComponents();
            addComponentListeners();
            otherInit();
        }

        public TransferMenu() {
            init();
        }

        @Override
        public void initializeComponents() {
            uploadItem = new JMenuItem("Upload");
            downloadItem = new JMenuItem("Download Selected");
        }

        @Override
        public void addComponents() {
            add(uploadItem);
            add(downloadItem);
        }

        @Override
        public void addComponentListeners() {
            uploadItem.addMouseListener(new UploadListener());
            downloadItem.addMouseListener(new DownloadListener());
            
        }

        @Override
        public void otherInit() {
            setText("Transfer");
            ApplicationController.getSplashScreen().incrementProgress();
        }

        @Override
        public void setLayouts() {
        }
    }

    private class ModifyMenu extends JMenu implements GUILoader {

        private JMenuItem deleteItem;

        private void init() {
            initializeComponents();
            setLayouts();
            addComponents();
            addComponentListeners();
            otherInit();
        }

        public ModifyMenu() {
            init();
        }

        @Override
        public void initializeComponents() {
            deleteItem = new JMenuItem("Delete Selected");
        }

        @Override
        public void addComponents() {
            add(deleteItem);
        }

        @Override
        public void addComponentListeners() {
            deleteItem.addMouseListener(new DeleteListener());
        }

        @Override
        public void otherInit() {
            setText("Modify");
            ApplicationController.getSplashScreen().incrementProgress();
        }

        @Override
        public void setLayouts() {
        }
    }
}
